This patch adds value checking of sched-credit xm options.
authorEmmanuel Ackaouy <ack@xensource.com>
Thu, 21 Sep 2006 13:10:56 +0000 (14:10 +0100)
committerEmmanuel Ackaouy <ack@xensource.com>
Thu, 21 Sep 2006 13:10:56 +0000 (14:10 +0100)
Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xm/main.py

index 94fadcf84d80f038b8df37491a7d0d440ea1341f..b434cb11867c46d975b1867a329672e098a1dad4 100644 (file)
@@ -560,13 +560,23 @@ class XendDomain:
         except Exception, ex:
             raise XendError(str(ex))
     
-    def domain_sched_credit_set(self, domid, weight, cap):
+    def domain_sched_credit_set(self, domid, weight = None, cap = None):
         """Set credit scheduler parameters for a domain.
         """
         dominfo = self.domain_lookup_by_name_or_id_nr(domid)
         if not dominfo:
             raise XendInvalidDomain(str(domid))
         try:
+            if weight is None:
+                weight = int(0)
+            elif weight < 1 or weight > 65535:
+                raise XendError("weight is out of range")
+
+            if cap is None:
+                cap = int(~0)
+            elif cap < 0 or cap > dominfo.getVCpuCount() * 100:
+                raise XendError("cap is out of range")
+
             return xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)
         except Exception, ex:
             raise XendError(str(ex))
index aafdf2de3462dc585ff5cda94066a5f5948089e6..0beb00e6e2802a504bb9134865ec8b0834dd1f21 100644 (file)
@@ -822,11 +822,6 @@ def xm_sched_credit(args):
     if weight is None and cap is None:
         print server.xend.domain.sched_credit_get(domain)
     else:
-        if weight is None:
-            weight = int(0)
-        if cap is None:
-            cap = int(~0)
-
         err = server.xend.domain.sched_credit_set(domain, weight, cap)
         if err != 0:
             print err